-- Setup data used in other tests
CREATE FUNCTION dbo.babel_3268_fn_1 () RETURNS int AS BEGIN RETURN 10 END
GO
CREATE FUNCTION dbo.babel_3268_fn_2 (@param INT) RETURNS int AS BEGIN RETURN @param * @param END
GO
CREATE FUNCTION dbo.babel_3268_fn_3 () RETURNS NVARCHAR AS BEGIN RETURN 'testing babel_3268' END
GO

CREATE TABLE babel_3268_t1 (a INT, b INT)
INSERT INTO babel_3268_t1 (a) VALUES (1)

CREATE TABLE babel_3268_t3 (a INT, b INT)
INSERT INTO babel_3268_t3 (a) VALUES (3)

CREATE TABLE babel_3268_t5 (a INT, b INT)
INSERT INTO babel_3268_t5 (a) VALUES (4)

CREATE TABLE babel_3268_t7 (a INT, b INT, c NVARCHAR(100))
INSERT INTO babel_3268_t7 (a) VALUES (1)

CREATE TABLE babel_3268_t8 (a INT, b INT, c NVARCHAR(100))
INSERT INTO babel_3268_t8 (a) VALUES (1)
GO

---- Create table test cases ----

-- Create table with Default
CREATE TABLE babel_3268_t2 (a int, b int DEFAULT dbo.babel_3268_fn_1())
INSERT INTO babel_3268_t2 (a) VALUES (1)
GO

--Create table default function uses parameters
CREATE TABLE babel_3268_t4 (a INT DEFAULT dbo.babel_3268_fn_2(-2), b int)
INSERT INTO babel_3268_t4 (b) VALUES (1)
GO

--CREATE table multiple defaults
CREATE TABLE babel_3268_t6 (a INT CONSTRAINT babel_3268_constraint DEFAULT dbo.babel_3268_fn_1(), b INT DEFAULT dbo.babel_3268_fn_1(), c TEXT )
INSERT INTO babel_3268_t6 (b) VALUES (1)
GO

---- Alter table test cases ----

-- Alter table add default
ALTER TABLE babel_3268_t1 ADD DEFAULT dbo.babel_3268_fn_1() FOR b
GO

--Alter table full TSQL Syntax
ALTER TABLE babel_3268_t3 ADD CONSTRAINT babel_3268_fn_1_constraint DEFAULT dbo.babel_3268_fn_1() FOR a;
GO

--ALTER table default function uses parameters
ALTER TABLE babel_3268_t5 ADD DEFAULT dbo.babel_3268_fn_2(100) FOR b
GO

--ALTER table multiple defaults NOTE: will raise an error because of an unrelated bug BABEL-3524
ALTER TABLE babel_3268_t7 ADD CONSTRAINT babel_3268_fn_2_constraint DEFAULT dbo.babel_3268_fn_2(90) FOR b, CONSTRAINT babel_3268_fn_3_constraint DEFAULT dbo.babel_3268_fn_3() FOR c;
GO
ALTER TABLE babel_3268_t8 ADD DEFAULT dbo.babel_3268_fn_2(90) FOR b, DEFAULT dbo.babel_3268_fn_3() FOR c;
GO